label: Be more selective when selecting on focus-in
authorMatthias Clasen <mclasen@redhat.com>
Sun, 2 Aug 2020 02:01:52 +0000 (22:01 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 2 Aug 2020 02:01:52 +0000 (22:01 -0400)
We don't want to select on focus-in when the focus
comes from a child. The case where this does harm
is when you activate copy or paste actions from the
context menu. We close the menu before triggering the
action, and if that causes the text in the label to
be selected, unexpected things happen, since the action
applies to the current selection.

This is the equivalent of cd9f5733b3e354301f2 for GtkLabel.

gtk/gtklabel.c

index 453f6023c7a218eb752f9cc67eb5ddf041fe323d..c39699fed1f9c0c1dd6f4d309d63f93a0fed5cb9 100644 (file)
@@ -3710,10 +3710,13 @@ gtk_label_grab_focus (GtkWidget *widget)
 {
   GtkLabel *self = GTK_LABEL (widget);
   gboolean select_on_focus;
+  GtkWidget *prev_focus;
 
   if (self->select_info == NULL)
     return FALSE;
 
+  prev_focus = gtk_root_get_focus (gtk_widget_get_root (widget));
+
   if (!GTK_WIDGET_CLASS (gtk_label_parent_class)->grab_focus (widget))
     return FALSE;
 
@@ -3724,12 +3727,14 @@ gtk_label_grab_focus (GtkWidget *widget)
                     &select_on_focus,
                     NULL);
 
-      if (select_on_focus && !self->in_click)
+      if (select_on_focus && !self->in_click &&
+          !(prev_focus && gtk_widget_is_ancestor (prev_focus, widget)))
         gtk_label_select_region (self, 0, -1);
     }
   else
     {
-      if (self->select_info->links && !self->in_click)
+      if (self->select_info->links && !self->in_click &&
+          !(prev_focus && gtk_widget_is_ancestor (prev_focus, widget)))
         {
           guint i;